/*
 * engine.h
 *
 *  Created on: Mar 30, 2012
 *      Author: The Almighty Eric
 */

#ifndef ENGINE_H
#define ENGINE_H
#include <string>
#include <list>
#include <vector>
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#include "Timer.h"
#include "Camera.h"

#define FLIP_VERTICAL 1
#define FLIP_HORIZONTAL 2

#define EDITOR 3
#define MAPTEST 4
#define CONSOLE 5

struct lrecord
{
	bool vis;
	int layer;

	lrecord(bool v, int l)
	{
		vis = v;
		layer = l;
	}
};

class engine
{
public:

	//Variables
	int winw, winh;
	bool quit;
	int state;
	//coordinates of mouse relative to window
	int mousex, mousey;
	//coordinates of mouse relative to window before update
	int lmx, lmy;
	//Relative coords of mouse based on camera
	int mxrel, myrel;

	int elayer;
	std::list<lrecord> layers;

	Camera c;
	SDL_Event event;
	SDL_Surface *background;
	SDL_Surface *screen;
	SDL_Surface *text;
	TTF_Font *font;
	Timer timer;


	engine();
	bool Init();

	//Program State functions
	int getState();
	void setState(int i);

	//Graphical
	void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip);
	SDL_Surface *load_image(std::string filename);
	void setColorKeyT(SDL_Surface *surface, Uint32 pixel);
	Uint32 getPixel(SDL_Surface *surface, int x, int y);
	void setPixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
	SDL_Surface *FlipImage(SDL_Surface *source, int flags);
	void printS(SDL_Surface *screen, float x, float y, std::string s);

	//Text
	void setFont(std::string filename, int fontsize);

	//Collision
	bool CollisionCheck(SDL_Rect A, SDL_Rect B);
	bool CollisionCheckPP(std::vector<SDL_Rect> A, std::vector<SDL_Rect> B);
	bool CollisionCheckCirc();

	//Mouse
	void updatexy(int x, int y);
	void updaterelative(int x, int y);
	void getxy(int* x, int* y);
	void getxyrel(int* x, int* y);

	//Camera
	void camreset(int w, int h);
	void camupdate(int x, int y);
	void camgetxy(int* x, int* y);

	//Layer control
	void newlayer(int i);
	void showLayer(int i);
	void hideLayer(int i);
	bool islayer(int i);

	//Cleanup
	bool breakdown();

};

#endif
